<?php
class zendacl
{
    private $role;     //角色
    private $resource; //资源
    private $action;   //动作
    private $acl;
   
    public function __construct($role,$res,$ac)
    {
        $this->role = $role;
        $this->resource = $res;
        $this->action = $ac;
    }
   
    public function initAcl()
    {
        $acl = new Zend_Acl();
        $acArr = $this->setParam();
		//print_r($acArr);
        $acl->addRole(new Zend_Acl_Role($this->role));
        foreach ($this->resource as $resource) {
            $acl->add(new Zend_Acl_Resource($resource));}
        foreach ($this->resource as $resource) {
			if(sizeof($acArr[$resource])==0){
			$acl->allow($this->role,$resource,"0000");	
				}
			else{
            $acl->allow($this->role,$resource,$acArr[$resource]);
			}
			}
        $strAcl = serialize($acl);
		return $strAcl;
    }
   
    public function saveAcl()
    {
        $acl = $this->acl;
        $strAcl = serialize($acl);
		return $strAcl;
       
    }
   
    public function setParam()
    {
        $action = $this->action;
        foreach ($action as $key => $value) {			
            $rowArr = explode('_', $value);
            $acArr[$rowArr[0]][$key] = $rowArr[1];
        }
        return $acArr;
    }
   

}